package NC;

public class NC9 {
    public boolean hasPathSum (TreeNode root, int sum) {
        // write code here
        return dfs(root,sum);
    }
    public static boolean dfs(TreeNode root, int sum ){
        if (root == null) return false;
        sum-=root.val;
        if (root.left == null && root.right == null && sum==0){
            return true;
        }
        return dfs(root.left,sum)||dfs(root.right,sum);
    }
}
